<!-- Vue3 语法 -->
<template>
  <div class="person">
    <h2>姓名: {{ person.name }}</h2>
    <h2>年龄: {{ person.age }}</h2>
    <button @click="changeName">修改名字</button>
    <button @click="changeAge">修改年龄</button>
  </div>
</template>
<script>
export default {
  name: "Person",
};
</script>
<script setup name="Person">
import { reactive, toRefs,toRef} from "vue";
/**
 * toRefs() 接受一个由reactive对象,将其结构出来且仍然是响应式.
 * toRefs(person)可以将对象结构出去
 */
let person = reactive({
  name: "张三",
  age: 18,
});
let {name,age} = toRefs(person);
// 从person中取出age且结构出的数据为响应式数据.
let nl = toRef(person,'age');

function changeName() {
  person.name += "~";
}
function changeAge() {
  person.age += 1;
}
</script>

<style>
li {
  font-size: 20px;
}
button {
  margin: 0 5px;
}
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
</style>
